package org.deng.vertx.web.verticle;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author: DengLibin
 * @Date: Create in 2022-04-30 15:23:14
 * @Description:
 */
@Slf4j
public class MainVerticle extends AbstractVerticle {

    @Override
    public void start() throws Exception {

        WebVerticle verticle = new WebVerticle();
        Future<String> future = vertx.deployVerticle(verticle);
        future.onSuccess(s -> log.info("WebVerticle部署完成:{}", s));

        deployHelloVerticle();

        //deployDaoVerticle();

    }

    /**
     * 部署verticle
     */
    private void deployHelloVerticle() {
        // 部署参数
        DeploymentOptions options = new DeploymentOptions();
        options.setWorker(true) // 设置为WorkerVerticle
                .setInstances(8); // 实例数 运行在多个线程上, 每个实例的start方法都会被调用; 事件总线上的消息会分配给某个实例处理，不会重复处理
        vertx.deployVerticle(HelloVerticle.class, options)
                .onSuccess(s -> {
                    log.info("HelloVeticle部署完成:{}", s);
                });
    }



    private void deployDaoVerticle(){
          // 部署参数
          DeploymentOptions options = new DeploymentOptions();
          options.setWorker(true) // 设置为WorkerVerticle
                  .setInstances(8); // 实例数
          vertx.deployVerticle(DaoVerticle.class, options)
                  .onSuccess(s -> {
                      log.info("DaoVerticle部署完成:{}", s);
                  });
    }
}
